home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / samples / Hector1600 / UnsignedDiv.asm < prev    next >
Assembly Source File  |  1995-07-26  |  2KB  |  80 lines

  1. ;
  2. ; ECE463 Unsigned Division
  3. ;
  4. ; Coded by: Bradford W. Mott
  5. ;           September 8,1993
  6. ;
  7.  
  8.           .org 0000
  9.  
  10.           move #512,sp
  11.           move #0,r0            ; Init Loop Variable
  12.  
  13. loop:     cmp  #num_els,r0      ; Check to see if we're finished
  14.           bra  finished,.eq
  15.  
  16.           move r0,r1
  17.           add  r1,r1
  18.  
  19.           move [r1,data1],r7    ; Get the dividend
  20.           move [r1,data1+1],r8
  21.           move [r0,data2],r9    ; Get the divisor
  22.           jsr  divide           ; divide the two numbers
  23.  
  24.           move r10,[r1,result]
  25.           move r11,[r1,result+1]
  26.  
  27.           inc  r0
  28.           bra  loop
  29.  
  30. finished: stop
  31.  
  32.  
  33. divide:   clr  r10              ; quot
  34.  
  35.           move #16,r13          ; Init the counter
  36.  
  37. dloop:    clc
  38.           rol  r10              ; quot := Bshl(quot,0,C)
  39.  
  40.           clc
  41.           rol  r8               ; loDvnd := Bshl(loDvnd,0,C)
  42.           rol  r7               ; hiDvnd := Bshl(hiDvnd,C,C)
  43.  
  44.           move #0,r12
  45.           bra  no_flag,.cc
  46.           move #1,r12       
  47.  
  48. no_flag:  sec
  49.           not  r9
  50.           addc r9,r7            ; hiDvnd := Badd(hiDvnd,Bcom(dvsr),1,C)
  51.  
  52.           bra  no_flag2,.cc
  53.           move #1,r12
  54.  
  55. no_flag2: not  r9
  56.           cmp #1,r12
  57.           bra  set_bit,.eq
  58.  
  59.           clc
  60.           addc r9,r7            ; hiDvnd := Badd(hiDvnd,dvsr,0,C)
  61.           bra  next
  62.  
  63. set_bit:  or #1,r10
  64.  
  65. next:     dec  r13
  66.           bra  dloop,.ne
  67.  
  68.           move r7,r11
  69.  
  70.           rts                   ; That's All
  71.  
  72.  
  73.           .org  256
  74.  
  75. num_els:  .equ  3
  76. data1:    .word 0x0000,0x0064,0x0000,0x00FF,0x00FF,0xFFFF
  77. data2:    .word        0x000A,       0x000F,       0x0F00
  78. result:   .rmw  num_els+num_els
  79.  
  80.